import { UserOrders } from './userOrder';
let _UserOrders = UserOrders;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import UserOrderMock from './mk/mng/computed/day/userOrderMock';
 * UserOrderMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/computed/day/userOrder/listKey').reply(config => {
      let params = config.params;
      let mockUserOrders = _UserOrders.filter(userOrder => {
      	if(params.orderTotalFee||params.orderTotalFee==''){ if( userOrder.orderTotalFee.indexOf(params.orderTotalFee)>=0) return true;}
      	if(params.orderTotalAmount||params.orderTotalAmount==''){ if( userOrder.orderTotalAmount.indexOf(params.orderTotalAmount)>=0) return true;}
      	if(params.orderActPayAmount||params.orderActPayAmount==''){ if( userOrder.orderActPayAmount.indexOf(params.orderActPayAmount)>=0) return true;}
      	if(params.orderReduceAmount||params.orderReduceAmount==''){ if( userOrder.orderReduceAmount.indexOf(params.orderReduceAmount)>=0) return true;}
      	if(params.custId||params.custId==''){ if( userOrder.custId.indexOf(params.custId)>=0) return true;}
      	if(params.bizDate||params.bizDate==''){ if( userOrder.bizDate.indexOf(params.bizDate)>=0) return true;}
      	if(params.actStaffFee||params.actStaffFee==''){ if( userOrder.actStaffFee.indexOf(params.actStaffFee)>=0) return true;}
      	if(params.startComputedDate||params.startComputedDate==''){ if( userOrder.startComputedDate.indexOf(params.startComputedDate)>=0) return true;}
      	if(params.shopCount||params.shopCount==''){ if( userOrder.shopCount.indexOf(params.shopCount)>=0) return true;}
      	if(params.id||params.id==''){ if( userOrder.id.indexOf(params.id)>=0) return true;}
      	if(params.custName||params.custName==''){ if( userOrder.custName.indexOf(params.custName)>=0) return true;}
      	if(params.computedStatus||params.computedStatus==''){ if( userOrder.computedStatus.indexOf(params.computedStatus)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockUserOrders
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/computed/day/userOrder/list').reply(config => {
      let params = config.params;
      let mockUserOrders = _UserOrders.filter(userOrder => {
      	var isTrue=false;
      	if(params.orderTotalFee||params.orderTotalFee==''){if(userOrder.orderTotalFee.indexOf(params.orderTotalFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderTotalAmount||params.orderTotalAmount==''){if(userOrder.orderTotalAmount.indexOf(params.orderTotalAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderActPayAmount||params.orderActPayAmount==''){if(userOrder.orderActPayAmount.indexOf(params.orderActPayAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderReduceAmount||params.orderReduceAmount==''){if(userOrder.orderReduceAmount.indexOf(params.orderReduceAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.custId||params.custId==''){if(userOrder.custId.indexOf(params.custId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bizDate||params.bizDate==''){if(userOrder.bizDate.indexOf(params.bizDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.actStaffFee||params.actStaffFee==''){if(userOrder.actStaffFee.indexOf(params.actStaffFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.startComputedDate||params.startComputedDate==''){if(userOrder.startComputedDate.indexOf(params.startComputedDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shopCount||params.shopCount==''){if(userOrder.shopCount.indexOf(params.shopCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(userOrder.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.custName||params.custName==''){if(userOrder.custName.indexOf(params.custName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.computedStatus||params.computedStatus==''){if(userOrder.computedStatus.indexOf(params.computedStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockUserOrders
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockUserOrders.length;
      mockUserOrders = mockUserOrders.filter((userOrder, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockUserOrders,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/computed/day/userOrder/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _UserOrders = _UserOrders.filter(userOrder => userOrder.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/computed/day/userOrder/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _UserOrders = _UserOrders.filter(userOrder => !params.includes(userOrder.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/computed/day/userOrder/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { orderTotalFee,orderTotalAmount,orderActPayAmount,orderReduceAmount,custId,bizDate,actStaffFee,startComputedDate,shopCount,id,custName,computedStatus } = params;
      _UserOrders.some(userOrder => {
        if (userOrder.id === id) {
			userOrder.orderTotalFee = orderTotalFee;
			userOrder.orderTotalAmount = orderTotalAmount;
			userOrder.orderActPayAmount = orderActPayAmount;
			userOrder.orderReduceAmount = orderReduceAmount;
			userOrder.custId = custId;
			userOrder.bizDate = bizDate;
			userOrder.actStaffFee = actStaffFee;
			userOrder.startComputedDate = startComputedDate;
			userOrder.shopCount = shopCount;
			userOrder.id = id;
			userOrder.custName = custName;
			userOrder.computedStatus = computedStatus
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/computed/day/userOrder/add').reply(config => {
      var params = JSON.parse( config.data );
      let { orderTotalFee,orderTotalAmount,orderActPayAmount,orderReduceAmount,custId,bizDate,actStaffFee,startComputedDate,shopCount,id,custName,computedStatus } = params;
      _UserOrders.push({
		orderTotalFee:orderTotalFee,
		orderTotalAmount:orderTotalAmount,
		orderActPayAmount:orderActPayAmount,
		orderReduceAmount:orderReduceAmount,
		custId:custId,
		bizDate:bizDate,
		actStaffFee:actStaffFee,
		startComputedDate:startComputedDate,
		shopCount:shopCount,
		id:id,
		custName:custName,
		computedStatus:computedStatus
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};